package com.ruoyi.deeplearn.service.impl;

import java.util.List;

import cn.hutool.core.util.IdUtil;
import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.deeplearn.domain.DeepDataset;
import com.ruoyi.deeplearn.service.IDeepDatasetService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.ruoyi.deeplearn.mapper.DeepDatasetGroupMapper;
import com.ruoyi.deeplearn.domain.DeepDatasetGroup;
import com.ruoyi.deeplearn.service.IDeepDatasetGroupService;

/**
 * 数据集组Service业务层处理
 *
 * @author rww
 * @date 2022-12-10
 */
@Service
public class DeepDatasetGroupServiceImpl implements IDeepDatasetGroupService
{
    @Autowired
    private DeepDatasetGroupMapper deepDatasetGroupMapper;
    @Autowired
    private IDeepDatasetService deepDatasetService;

    /**
     * 查询数据集组
     *
     * @param id 数据集组主键
     * @return 数据集组
     */
    @Override
    public DeepDatasetGroup selectDeepDatasetGroupById(Long id)
    {
        return deepDatasetGroupMapper.selectDeepDatasetGroupById(id);
    }

    /**
     * 查询数据集组列表
     *
     * @param deepDatasetGroup 数据集组
     * @return 数据集组
     */
    @Override
    public List<DeepDatasetGroup> selectDeepDatasetGroupList(DeepDatasetGroup deepDatasetGroup)
    {
        return deepDatasetGroupMapper.selectDeepDatasetGroupList(deepDatasetGroup);
    }

    /**
     * 新增数据集组
     *
     * @param deepDatasetGroup 数据集组
     * @return 结果
     */
    @Override
    public int insertDeepDatasetGroup(DeepDatasetGroup deepDatasetGroup)
    {
        deepDatasetGroup.setCreateTime(DateUtils.getNowDate());
        return deepDatasetGroupMapper.insertDeepDatasetGroup(deepDatasetGroup);
    }

    /**
     * 修改数据集组
     *
     * @param deepDatasetGroup 数据集组
     * @return 结果
     */
    @Override
    public int updateDeepDatasetGroup(DeepDatasetGroup deepDatasetGroup)
    {
        deepDatasetGroup.setUpdateTime(DateUtils.getNowDate());
        return deepDatasetGroupMapper.updateDeepDatasetGroup(deepDatasetGroup);
    }

    /**
     * 批量删除数据集组
     *
     * @param ids 需要删除的数据集组主键
     * @return 结果
     */
    @Override
    public int deleteDeepDatasetGroupByIds(Long[] ids)
    {
//        return deepDatasetGroupMapper.deleteDeepDatasetGroupByIds(ids);
        for(int i=0;i<ids.length;i++){
            deleteDeepDatasetGroupById(ids[i]);
        }
        return ids.length;
    }

    /**
     * 删除数据集组信息
     *
     * @param id 数据集组主键
     * @return 结果
     */
    @Override
    public int deleteDeepDatasetGroupById(Long id)
    {
        deepDatasetService.deleteDeepDatasetByDatasetGroupId(id);
        return deepDatasetGroupMapper.deleteDeepDatasetGroupById(id);
    }

    @Override
    public int createDatasetGroup(DeepDatasetGroup deepDatasetGroup) {
        deepDatasetGroup.setId(IdUtil.getSnowflakeNextId());
        insertDeepDatasetGroup(deepDatasetGroup);
        DeepDataset deepDataset = new DeepDataset();
        deepDataset.setId(IdUtil.getSnowflakeNextId());
//        deepDataset.setName(deepDatasetGroup.getName());
        deepDataset.setDatasetGroup(deepDatasetGroup.getId());
        deepDataset.setVersion(1);
        deepDataset.setModuleId(deepDatasetGroup.getModuleId());
//        deepDataset.setDatasetType(deepDatasetGroup.getDataType());
        deepDatasetGroup.setCurrentDatasetId(deepDataset.getId());
        updateDeepDatasetGroup(deepDatasetGroup);
        deepDatasetService.insertDeepDataset(deepDataset);
        return 1;
    }
}
